package com.heiyu.api.controller;

import com.heiyu.api.response.NoticeResponse;
import com.heiyu.api.response.model.NoticeModel;
import com.heiyu.controller.ApiBaseController;
import com.heiyu.dao.NoticeInfoMapper;
import com.heiyu.entity.NoticeInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@RestController
@RequestMapping("api/v1/notice")
public class NoticeController extends ApiBaseController {

    @Autowired
    private NoticeInfoMapper noticeInfoMapper;

    @ApiOperation(value = "get",notes = "获取公告信息，只会给最新一条公告，本地需要把公告id进行保存拿到的时候如果是已经展示过的公告不再做展示")
    @GetMapping("get")
    public NoticeResponse getNotice(){
        NoticeResponse response = new NoticeResponse();
        response.success();
        response.setData(new NoticeModel());
        NoticeInfo noticeInfo = noticeInfoMapper.getLastNoticeInfo();
        if(noticeInfo != null){
            response.getData().setContent(noticeInfo.getContent());
            response.getData().setTargetUrl(noticeInfo.getTargetUrl());
            response.getData().setNoticeId(noticeInfo.getId());
        }
        return response;
    }
}
